---
layout: "default"
root: "/v5.1"
description: "Swift documentation for 'ExpressibleByIntegerLiteral'"
title: "ExpressibleByIntegerLiteral"
keywords: ""
---

<div class="intro-declaration"><code class="language-swift">protocol ExpressibleByIntegerLiteral</code></div><p>A type that can be initialized with an integer literal.</p>
<table class="standard"><tr><th id="conforming-types">Conforming Types</th><td><code class="inherits">Double, Float, Float80, Numeric</code></td></tr><tr><th id="associatedtypes">Associated Types</th><td><span id="aliasesmark"></span><div class="declaration"><code class="language-swift">associatedtype IntegerLiteralType</code><div class="comment"><p>The standard library integer and floating-point types are all valid types
for <code>IntegerLiteralType</code>.</p>
</div></div></td></tr></table><div class="discussion comment"><p>The standard library integer and floating-point types, such as <code>Int</code> and
<code>Double</code>, conform to the <code>ExpressibleByIntegerLiteral</code> protocol. You can
initialize a variable or constant of any of these types by assigning an
integer literal.</p>
<pre><code class="language-swift">// Type inferred as 'Int'
let cookieCount = 12

// An array of 'Int'
let chipsPerCookie = [21, 22, 25, 23, 24, 19]

// A floating-point value initialized using an integer literal
let redPercentage: Double = 1
// redPercentage == 1.0
</code></pre>
<h3>Conforming to ExpressibleByIntegerLiteral</h3>
<p>To add <code>ExpressibleByIntegerLiteral</code> conformance to your custom type,
implement the required initializer.</p>
</div><h3>Initializers</h3><div id="init_integerLiteral-82f4c43a2d364fab74b9e9bd1c193e2e" class="declaration"><a class="toggle-link" href="#comment-init_integerLiteral-82f4c43a2d364fab74b9e9bd1c193e2e">init init(integerLiteral:)</a> <span class="required">Required</span><div class="comment collapse in" id="comment-init_integerLiteral-82f4c43a2d364fab74b9e9bd1c193e2e"><p>Creates an instance initialized to the specified integer value.</p>
<p>Do not call this initializer directly. Instead, initialize a variable or
constant using an integer literal. For example:</p>
<pre><code class="language-swift">let x = 23
</code></pre>
<p>In this example, the assignment to the <code>x</code> constant calls this integer
literal initializer behind the scenes.</p>
<ul>
<li>Parameter value: The value to create.</li>
</ul>
<h4>Declaration</h4><code class="language-swift">init(integerLiteral value: Self.IntegerLiteralType)</code></div></div>